import Vue from "vue";
import Vuex from "vuex";

import router from "../router"; //导入路由对象

Vue.use(Vuex);

// 配置插件      
import VuexPersistence from 'vuex-persist' //导入持久化插件

//实例化vuex持久化对象
const VuexLocal = new VuexPersistence({
  //制定存储的地方
  storage: window.localStorage,
  //vuex存储的key值
  key: "04b_vuex",
});


export default new Vuex.Store({
  state: {
    //管理后台存储的信息
    baseUrl: "https://www.liulongbin.top:8888/api/private/v1/",
    admin_user: {},
    admin_token: "", //管理后台的token

    bread:[],//面包屑管理后台
  },
  mutations: {
    //管理后台的vuex的操作
                     login(state, user) {
      //设置token值和user值
      state.admin_user = user;
      state.admin_token = user.token;
    },
    //执行退出的操作
    logout(state) {
      state.admin_token = "";
      state.admin_user = {};
      console.log('残忍执行了退出的操作');
      router.push("/admin/login"); //直接跳转页面到登陆
    },
    //设置面包屑
    setBread(state,bread){
      state.bread = bread;
    }
  },
  actions: {},
  modules: {},
  plugins: [VuexLocal.plugin],
});